<?php
namespace Admin\Controller;
use Tools\AdminController;
class ShopController extends AdminController {
   function indexslides(){//首页轮播图设置
   		$slides=D('slides')->where("pos='indexslides'")->select();
//		var_dump($slides);
		$this->assign('slides',$slides);
   		$this->display();
   }
	function addindexslides(){
			if(!empty($_POST)){
//				var_dump($_POST);exit;
				//上传商品图片
				$cfg=array('rootPath'      => './upload/');
				$up=new \Think\Upload($cfg);
				$upload_result=$up->uploadOne($_FILES['image']);
				//图片路径
				$pic_path=$up->rootPath.$upload_result['savepath'].$upload_result['savename'];
				//修改为新的图片路径
				$_POST['image']=ltrim($pic_path,'.');
				$_POST['create_time']=$_SERVER['REQUEST_TIME'];
				$_POST['pos']='indexslides';
				if(D('slides')->add($_POST)){
					$this->success('Index/success');
					$this->redirect('Shop/indexslides',array(),1," ");
				}else{
					$this->error('Index/error');
					$this->redirect('Shop/indexslides',array(),1," ");
				}
				
			}else{
				$this->display();
			}
	}
	public function editindexslides($uid){
//			var_dump($_POST);var_dump($_FILES);exit;
			if(!empty($_POST)){
//				var_dump($_POST);exit;
				//上传商品图片
				$cfg=array('rootPath'      => './upload/');
				$up=new \Think\Upload($cfg);
				if($_FILES['image']['error']!=4){//判断是否上传了图片,不上传则不修改图片
				
					$upload_result=$up->uploadOne($_FILES['image']);
					//图片路径
					$pic_path=$up->rootPath.$upload_result['savepath'].$upload_result['savename'];
					//修改为新的图片路径
					$_POST['image']=ltrim($pic_path,'.');
				}
					$_POST['create_time']=$_SERVER['REQUEST_TIME'];
//					var_dump($_POST);
					if(D('slides')->save($_POST)){//成功
						$this->success('Index/success');
						$this->redirect('Shop/indexslides',array(),1," ");
					}else{//失败
						$this->error('Index/error');
						$this->redirect('Shop/indexslides',array(),1,' ');
					}
			}else{
				$slides=D('slides')->where("uid='$uid'")->find();
				//var_dump($info);
				$this->assign('slides',$slides);
				$this->display();
			}
	}
	public function deleteindexslides($uid){
//		$cats=new \Model\CatsModel();
//		$sql="delete from goods_cats where uid=$uid;";
//		if($cats->execute($sql)){
		if(D('slides')->where('uid='.$uid)->delete()){
			//$this->redirect('IntegralGoods/goalstore',array(),3);
			$this->success('Index/success');
			$this->redirect('Shop/indexslides',array(),1," ");
		}else{
			//$this->redirect('IntegralGoods/goalstore',array(),3,'success!back after 3s ');
			$this->error('Index/error');
			$this->redirect('Shop/indexslides',array(),1,' ');
		}
	}
	function sendmsg(){
		if(!empty($_POST)){
			$_POST['uid']=1;
			if(D('shop_msg')->save($_POST)){
			//$this->redirect('IntegralGoods/goalstore',array(),3);
				$this->success('Index/success');
				$this->redirect('Shop/sendmsg',array(),1," ");
			}else{
				$this->error('Index/error');
				$this->redirect('Shop/sendmsg',array(),1,' ');
			}
		}else{
			$msg_info=D('shop_msg')->where('uid=1')->find();
			$this->assign("msg_info",$msg_info);
			$this->display();
		}
	}
	 
}